﻿using System.ComponentModel.DataAnnotations;

namespace Forum.Model.Validation
{
    public class PhoneAttribute : ValidationAttribute
    {
        protected static string error = "手机号错误";
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            if (FormatValidation.IsPhoneNumber(value as string))
                return ValidationResult.Success;

            return new ValidationResult(ErrorMessage ?? error);
        }
    }
}
